package com.hqyj.controller;


import com.hqyj.pojo.Department;
import com.hqyj.service.IDepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

/**
 * <p>
 * 部门表 前端控制器
 * </p>
 *
 * @author rock
 * @since 2021-10-21
 */
@RestController
@RequestMapping("/department")
public class DepartmentController {
    @Autowired
    IDepartmentService departmentService;

    //管理用户列表
    @RequestMapping("/departmentList")
    public HashMap<String,Object> departmentListPage(Department department){
        HashMap<String,Object> map = departmentService.queryAll(department);
        return map;
    }

    @RequestMapping("/updateDepartment")
    public HashMap<String, Object> updateDepartment(Model model, Department department){
        HashMap<String, Object> map = departmentService.update(department);
        if(map.get("info").equals("保存成功")){
            model.addAttribute("info","保存成功");
        }else {
            model.addAttribute("info", "保存失败");
        }
        return map;
    }

    @RequestMapping("/addDepartment")
    public HashMap<String, Object> addDepartment(Model model, Department department){
        HashMap<String, Object> map = departmentService.addDepartment(department);
        if(map.get("info").equals("保存成功")){
            model.addAttribute("info","保存成功");
        }else {
            model.addAttribute("info", "保存失败");
        }
        return map;
    }
    @RequestMapping("/delDepartment")
    public HashMap<String, Object> delDepartment(Integer id){
        return departmentService.delDepartment(id);
    }
}

